#!/usr/bin/perl 

use strict;
use DBI;
use CGI;
# use TTrakerSite;
use TTraker;

my $dbh;
& initialize_dbi;
& print_header;

my $query = CGI->new;
my $supNum = $query->param('supNum');
my $supName = $query->param('supName');
my $supJob = $query->param('supJob');
my $supLoc = $query->param('supLoc');
my $empNum = $query->param('empNum');
my $empName = $query->param('empName');
my $payDate = $query->param('payDate');
my $empFac = $query->param('empFac');
my $cleanDirty = $query->param('cleanDirty');

my $tc_chk = check_tc_tmp_data ($supNum, $empNum, $payDate);

# print "THERE ARE $tc_chk EVENTS<br/>";

if ( $tc_chk > 0 ) {

my $it = update_iteration ($supNum, $empNum, $payDate);

deactivate_job_events ($supNum, $empNum, $payDate);
write_new_dirty_job_events ($supNum, $empNum, $payDate);
clear_day_events ($empNum, $payDate);
create_day_event ($empNum, $payDate);
clear_useless_iterations ($empNum, $payDate, $it); 
set_time_adj_to_one ($empNum, $payDate);
 

# create_job_events_history ($supNum, $empNum, $payDate);

# die "Alan says: Put your left foot in";

# generate_dirty_time_card_events ($supNum, $empNum, $payDate);

#	generate_day_event ($supNum, $empNum, $payDate);
#	generate_doc_headers ($supNum, $empNum, $payDate);
#	generate_job_events ($supNum, $empNum, $payDate);
}	

time_card_specs($supNum, $supName, $supJob, $supLoc, $empFac);


db_disconnect();

##################### SUBROUTINES FOLLOW  #####################

sub time_card_specs 
{
	my $supNum = $_[0];
	my $supName = $_[1];
	my $supJob = $_[2];
	my $supLoc = $_[3];
	my $loc = $_[4];
	my $date;
 	my @payDates=();		
	my $payDates_ref = get_payroll_dates;
   @payDates = @$payDates_ref;
	my @facility=(); 
   my $facility_ref = get_facilities();
	my @facility = @$facility_ref;
	print <<ENDHEADER;
	<html>
	<head>
	<link rel='stylesheet' type='text/css' href='${css_ref}trak.css' />
	<script type='text/javascript' src='${js_ref}trak.js'></script>
	<title>trak_02_sup_activity_select_payroll_date</title>
	</head>
	<body onload='startUp1()'>
	<h2><center>${banner}</center></h2>
	<hr/>
	<div id='clock'></div>
	<div id='box1'>
	Employee Number:<br/><br/>
	Employee Name:<br/><br/>
	</div>
	<form id='box2' autocomplete='off' name='startJob' action='${cgi_ref}trak_03_sup_time_card_data.pl' method='post'>
	<input type="hidden" name=supNum value='$supNum'/>
	<input type="hidden" name=supName value='$supName'/>
	<input type="hidden" name=supJob value='$supJob'/>
	<input type="hidden" name=supLoc value='$supLoc'/>
	<input type="hidden" name=payDate value='$payDate'/>
	<input type="hidden" name=empFac value='$empFac'/>
	<span>$supNum</span><br/><br/>
	<span>$supName</span></b><br/><br/>
	<table cellspacing = "4" cellpadding="6">
		<tr>
			<td>Employee Number: &nbsp</td>
			<td><input type="text" size=5 name="empNum" /></td>
		</tr>
		<tr>
			<td>Select Date:</td>
			<td>
				<select style="width:120px" id=payDate name="payDate" tabindex=1 >
ENDHEADER
			foreach $date (@payDates) {
   			print "<option value=$date >$date</option>";
			}
print <<ENDHEADER;
			</td>
		</tr>
		</select>	
		<tr>
			<td>Location: &nbsp</td>
			<td><select style="width:120px" id=empFac name="empFac" tabindex=1 >
ENDHEADER
			# add default option
				print "<option value=0 >Home</option>";
			for (my $i=0;$i<=$#facility;$i++) {
				print "<option value=$facility[$i][0] >$facility[$i][1]</option>";
			}
			print <<ENDHEADER;
			</td>
		</tr>
		</select>
	</table>
<br/><br/>
<input type='submit' name='submit' value='Proceed'>
<br/><br/>
<a href="${cgi_ref}trak_00_sup_activity.pl?num=$supNum&name=$supName&job=$supJob&loc=$supLoc">Return to Activities</a>
<br/><br/>
</form>
</body>
</html>

ENDHEADER

}


